package com.pg.excel.util;

import java.io.*;
import java.util.Properties;

public class PropertiesUtils {
    private static PropertiesUtils ourInstance = new PropertiesUtils();

    public static PropertiesUtils getInstance() {
        return ourInstance;
    }

    private PropertiesUtils() {
    }

    private String getLastPathPath(){
        return System.getProperty("user.dir")+"\\lastPath.properties";
    }

    public String getLastPath() {
        try {
            Properties properties = new Properties();
            String filePath = getLastPathPath();
            InputStream in = new FileInputStream(new File(filePath));
            properties.load(in);
            return properties.getProperty("lastPath");
        }catch (Exception e){}
        return "";
    }

    public void setProperties(String value){
        OutputStream output = null;
        try {
            Properties properties = new Properties();
            properties.setProperty("lastPath", value);
            File outFile = new File(getLastPathPath());
            if (!outFile.exists()){
                outFile.createNewFile();
            }
            output = new FileOutputStream(outFile);
            properties.store(output,null);
            output.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (output != null) {
                try {
                    output.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
